package com.sysu.minsysu.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

import com.sysu.R;

public class AcademyDialog extends Dialog{
	
	TextView mTitleTextView;
	TextView mIntroduceTextView;
	Gallery mBigGallery;
	Gallery mSmallGallery;
	
	Bitmap[] mBitmaps;
	int mCurSelection=0;

	public AcademyDialog(Context context, String title, String intro, Bitmap[] bitmaps) {
		super(context, R.style.dialog);
		//super(context);
		setContentView(R.layout.compus_dialog);
		
		mTitleTextView = (TextView)findViewById(R.id.title);
		mIntroduceTextView = (TextView)findViewById(R.id.introduce);
		mBigGallery = (Gallery)findViewById(R.id.gallery1);
		mSmallGallery = (Gallery)findViewById(R.id.gallery2);
		
		mTitleTextView.setText(title);
		mIntroduceTextView.setText(intro);
		mBitmaps = bitmaps;
		
		//mBigGallery.setSpacing(19);		
		mBigGallery.setAdapter( new ImageAdapter(getContext(), mBitmaps));
		//mSmallGallery.setSpacing(1);
		mSmallGallery.setAdapter( new ImageAdapter(getContext(), mBitmaps));
		//mSmallGallery.
		mSmallGallery.setOnItemSelectedListener( new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				mCurSelection = arg2;
				if( mBigGallery.getSelectedItemPosition()!=mCurSelection)
					mBigGallery.setSelection(arg2, true);
			}
			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				
			}			
		});
		mBigGallery.setOnItemSelectedListener( new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				mCurSelection = arg2;
				if( mSmallGallery.getSelectedItemPosition()!=mCurSelection)
					mSmallGallery.setSelection(arg2, true);
			}
			@Override
			public void onNothingSelected(AdapterView<?> arg0) {				
			}			
		});
	}

}
